/**
*  \file cromo.h
*
*  \brief  Continous ROM Observer
*
*  \author Michael J. Hohmann <michael.hohmann@linde-mh.de>
*
*/

#ifndef CROMO_H_INCLUDED
#define CROMO_H_INCLUDED

/*================================================[ public includes  ]================================================*/
//#include "../cfg/prj.h"
#include "cromo_cfg.h"

/*================================================[ public defines   ]================================================*/
enum cromo_func_status
{
	cromo_func_status_first,
	cromo_func_status_pending,
	cromo_func_status_last,
};

/*================================================[ public datatypes ]================================================*/

/** Checksum function pointer type */
typedef cromo_cks_t ( *cromo_callback_t)(void * const start, U32 len, enum cromo_func_status status );


/** Cromo Object */
struct cromo
{
   cromo_data_t *pbegin;    /**< pointer to the start of the memory chunk                     */
   U32   len;               /**< number of words to be calculated                             */
   cromo_cks_t checksum;     /**< checksum of the memory area                                  */
   //cromo_cks_t cks_init;     /**< initial value of the checksum algorithm                      */
   cromo_callback_t function;/**< function pointer to a checksum function                      */
   S16 succeed;              /**< Amount of positive tests                                     */
   S16 failed;               /**< Amount of negative tests                                     */
   cromo_data_t * cursor;    /**< current position of the checksum function in the memory area */
   cromo_cks_t subtotal;     /**< current subtotal of the checksum function                    */
   U32 todo;                 /**< Number of bytes do be processed to reach end of memory block */
};
/*================================================[ public variables ]================================================*/

/*================================================[ public functions ]================================================*/

/** Test for memory integrity.
*
*  The function cromo_process() check the integrity of a a memory block.
*  This will happen in pieces of words, as passed as parameter.
*
*  \param me   Pointer to an existing and initialized cromo object.
*  \param size Number of word that will be processed.
*
*  \return  -Negative Values if one or more checks have failed.
*           - 0 - If at this point no check has been completed.
*           -Positive values of one or more check were successful but no check was failed.
*
*  \attention The function cromo_initialize() has to be called for each object once before use this function.
*/
S16 cromo_process( struct cromo *me, U32 size);

/** Get test status.
*
*  The function cromo_status() retrieve the current status of the memory check.
*
*  \param me   Pointer to an existing and initialized cromo object.
*
*  \return  -Negative Values if one or more checks have failed.
*           - 0 - If at this point no check has been completed.
*           -Positive values of one or more check were successful but no check was failed.
*
*  \attention The function cromo_initialize() has to be called for each object once before use this function.
*/
S16 cromo_status( struct cromo *me);

/** Initialize an Oberver object.
*
*  The function cromo_initialize() will initialize the passed observer object.
*
*  \param   me Object   pointer. It is save to pass NULL. Pass 0 will raise an assert.
*  \param   cks_init    The initialization value of the checksum algorithm.
*  \param   start       Pointer to the start of the memory area which will be observed. It is save to pass NULL.
*  \param   size        Size of the memory area (in words). It is save to pass zero.
*  \param   function    Function pointer to a checksum function. Pass 0 will
*
*  \return  Always RC_SUCCESS.
*/
RC cromo_initialize( struct cromo *me,  cromo_cks_t checksum, cromo_data_t *start,U32 size, cromo_callback_t function);

/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2009 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
